/**
 * Created by Joe on 2017/7/5 0005.
 */
var account = {
    fields: {
        selects: [], //下拉框
        radios: [],//单选框
        checkboxs: [],//复选款
        textareas: [],//多行文本框
        selfDefine: []
    }
};
$(document).ready(function () {

    $('#DataTables_partner_account').DataTable({
        "paging": true,
        "searching": true,
        "info": true,
        "ordering": true,
        "language": {
            "url": "../vendor/datatables/zh-cn.json"
        }
    });
    $('#btn-query').on('click', function () {
        requestQueryAccount();
    });
    $('#selectedCompany').change(function () {
        var companyName = $("#selectedCompany").find("option:selected").text();
    });
});

function requestQueryAccount() {
    $("#DataTables_partner_account").DataTable().rows().remove().draw();
    var companyId = $("#companyId").val();
    var url = /*[[@{/account/queryAccount}]]*/ '/account/queryAccount';
    Utils.ajaxSubmit(url + "/" + companyId, {}, function (data) {
        console.log("data ： ", data);
        if (data.result == "success") {
            addTableRow(data.content, "#DataTables_partner_account");
        }
        if (data.result == "fail") {
            Utils.errorAlert(data.errorMessage);
        }
    });
}

/**添加table行*/
function addTableRow(accountList, targetEle) {
    $.each(accountList, function (k, v) {
        addTableSingleRow(v, targetEle);
    });
}
function addTableSingleRow(v, targetEle) {
    var btnRemoveEle = "";
    /*var btnRemoveEle = '<input type="hidden" value="' + v.id + '"> <a class="btn btn-primary btn-detail" >查看明细</a>';
     btnRemoveEle = btnRemoveEle.concat('&nbsp;&nbsp;&nbsp;<a class="btn btn-danger btn-delete">删除</a>');*/
    $(targetEle).dataTable().fnAddData([v.accountNo, v.avlBalance, v.currentAmount, v.unsettledAmount, v.mbAmount, v.createAt, btnRemoveEle]);
}


